Skip to content

[test] Add tests for strutil.DeepCloneJSON#7232

Merged
lpcox merged 1 commit into
mainfrom
add-tests-strutil-deepclonejson-ad869d22173160f4
Jun 9, 2026
Merged

[test] Add tests for strutil.DeepCloneJSON#7232
lpcox merged 1 commit into
mainfrom
add-tests-strutil-deepclonejson-ad869d22173160f4

Conversation

@github-actions

@github-actions github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Test Coverage Improvement: DeepCloneJSON

Function Analyzed

  • Package: internal/strutil
  • Function: DeepCloneJSON
  • Previous Coverage: 0%
  • New Coverage: 100%
  • Complexity: Medium (recursive type-switch with 3 branches)

Why This Function?

DeepCloneJSON was the only function in the codebase with 0% coverage among testable packages. It has meaningful complexity: a recursive type-switch with three distinct branches (map cloning, slice cloning, and primitive pass-through), and the correctness of deep-clone independence is non-trivial to verify without explicit tests.

Tests Added

  • ✅ Primitive pass-through: nil, string, float64, bool (true and false)
  • ✅ Empty map and empty slice
  • ✅ Flat map with mixed primitive values
  • ✅ Flat slice with mixed primitive values
  • ✅ Deep clone independence for maps (mutations to clone don't affect original)
  • ✅ Deep clone independence for slices
  • ✅ Nested map deep cloning with independence verification
  • ✅ Nested slice deep cloning with independence verification
  • ✅ Map containing slices (cross-branch recursion)
  • ✅ Slice containing maps (cross-branch recursion)
  • ✅ Deeply nested structure (3+ levels) with independence verification
  • nil values within maps and slices
  • ✅ Map preserving all key-value pair types

Coverage Report

Before: 88.2% (strutil package) — DeepCloneJSON: 0.0%
After:  100.0% (strutil package) — DeepCloneJSON: 100.0%
Improvement: +11.8% (package), +100% (function)

Test Execution

All 21 tests pass:

--- PASS: TestDeepCloneJSON (0.00s)
    --- PASS: TestDeepCloneJSON/nil_input_returns_nil
    --- PASS: TestDeepCloneJSON/string_returns_same_value
    --- PASS: TestDeepCloneJSON/float64_returns_same_value
    --- PASS: TestDeepCloneJSON/bool_true_returns_same_value
    --- PASS: TestDeepCloneJSON/bool_false_returns_same_value
    --- PASS: TestDeepCloneJSON/empty_map_returns_empty_map
    --- PASS: TestDeepCloneJSON/flat_map_with_primitive_values
    --- PASS: TestDeepCloneJSON/flat_map_clone_is_independent_from_original
    --- PASS: TestDeepCloneJSON/nested_map_deep_clones_nested_maps
    --- PASS: TestDeepCloneJSON/nested_map_clone_is_independent_from_original
    --- PASS: TestDeepCloneJSON/empty_slice_returns_empty_slice
    --- PASS: TestDeepCloneJSON/flat_slice_with_primitive_values
    --- PASS: TestDeepCloneJSON/flat_slice_clone_is_independent_from_original
    --- PASS: TestDeepCloneJSON/nested_slice_deep_clones_nested_slices
    --- PASS: TestDeepCloneJSON/nested_slice_clone_is_independent_from_original
    --- PASS: TestDeepCloneJSON/map_containing_slices
    --- PASS: TestDeepCloneJSON/slice_containing_maps
    --- PASS: TestDeepCloneJSON/deeply_nested_structure
    --- PASS: TestDeepCloneJSON/map_with_null_value
    --- PASS: TestDeepCloneJSON/slice_with_null_element
    --- PASS: TestDeepCloneJSON/map_preserves_all_key-value_pairs
PASS
ok  	github.com/github/gh-aw-mcpg/internal/strutil	0.006s	coverage: 100.0% of statements

Generated by Test Coverage Improver
Next run will target the next most complex under-tested function

Warning

Firewall blocked 7 domains

The following domains were blocked by the firewall during workflow execution:

  • go.opentelemetry.io
  • go.yaml.in
  • golang.org
  • google.golang.org
  • gopkg.in
  • proxy.golang.org
  • releaseassets.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "go.opentelemetry.io"
    - "go.yaml.in"
    - "golang.org"
    - "google.golang.org"
    - "gopkg.in"
    - "proxy.golang.org"
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by Test Coverage Improver · sonnet46 2.3M ·

Add comprehensive table-driven tests for DeepCloneJSON covering:
- Primitive pass-through (nil, string, float64, bool)
- Empty and flat map cloning
- Empty and flat slice cloning
- Nested map and slice deep cloning
- Deep clone independence (mutations to clone don't affect original)
- Mixed structures (maps containing slices, slices containing maps)
- Deeply nested structures
- Null/nil values within collections

Improves strutil package coverage from 88.2% to 100.0%.
DeepCloneJSON specifically: 0% → 100%.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review June 9, 2026 13:53
Copilot AI review requested due to automatic review settings June 9, 2026 13:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds comprehensive unit tests for internal/strutil.DeepCloneJSON, covering primitive pass-through, map/slice cloning, mixed/nested structures, and clone-independence to eliminate the last uncovered function in internal/strutil.

Changes:

  • Introduces a new TestDeepCloneJSON suite with subtests for primitives, empty/flat/nested maps and slices, and mixed recursion (map↔slice nesting).
  • Verifies deep-clone independence by mutating cloned nested structures and asserting originals are unaffected.
Show a summary per file
File Description
internal/strutil/deepclone_test.go Adds full test coverage for DeepCloneJSON, including deep-independence checks across nested map/slice structures.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@lpcox lpcox merged commit 19f6573 into main Jun 9, 2026
24 checks passed
@lpcox lpcox deleted the add-tests-strutil-deepclonejson-ad869d22173160f4 branch June 9, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants